import java.util.Stack;

/**
 * @Author ZhangCuirong
 * @Date 2025/9/16 14:23
 * @description:
 */
public class Solution1047 {
    public String removeDuplicates(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            Character c = s.charAt(i);
            if(stack.isEmpty()){
                stack.add(c);
            }else{
                if(stack.peek() == c){
                    stack.pop();
                }else{
                    stack.push(c);
                }
            }

        }
        StringBuilder res = new StringBuilder();
        while (!stack.isEmpty()){
            res.append(stack.pop());
        }
        return res.reverse().toString();
    }

    public static void main(String[] args) {
        Solution1047 solution = new Solution1047();
        System.out.println(solution.removeDuplicates("abbaca"));
    }
}
